library(tidyverse)
## ── Attaching packages ───────────────────────────────────────────────────────────────────────────────────────── tidyverse 1.2.1 ──
## ✔ ggplot2 3.1.0 ✔ purrr 0.2.5
## ✔ tibble 1.4.2 ✔ dplyr 0.7.8
## ✔ tidyr 0.8.2 ✔ stringr 1.3.1
## ✔ readr 1.2.1 ✔ forcats 0.3.0
## ── Conflicts ──────────────────────────────────────────────────────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
library(ez)
library(data.table)
##
## Attaching package: 'data.table'
## The following objects are masked from 'package:dplyr':
##
## between, first, last
## The following object is masked from 'package:purrr':
##
## transpose
source('../../formatSimpleEffects.r')
This document is dedicated to conducting the analysis to test for evidence of the reference point shifting throughout the experiment.
Design. The design and analysis is a 2 (difficulty: harder than reference vs. easier than reference) X 2 (lagged difficulty: difficulty condition on previous block) within-subjects ANOVA on proportion selection of the reference deck.
Predictions. If the reference point moves as a function of what condition is being performed, then there should be a simple effect of lagged difficulty within the harder-than-reference condition, where selection of reference would be greater if the previous block was a harder-than-reference block rather than if it was an easier-than-reference block.
Below is the cleaned data:
d <- read.csv('../../../data/dstClean.csv')
n <- d %>%
group_by(subject) %>%
summarize(n()) %>%
nrow(.)
## code lagged difficulty
d <- d %>%
group_by(subject, block, cycle) %>%
summarize(difficulty = difficulty[1]) %>%
ungroup() %>%
mutate(lagDifficulty = lag(difficulty)) %>%
select(-difficulty) %>%
inner_join(d) %>%
mutate(trash = ifelse(block == 1 & cycle == 1, 1, 0)) %>%
filter(trash == 0) %>%
select(-trash)
## Joining, by = c("subject", "block", "cycle")
d <- d %>%
mutate(selRefDeck = ifelse(chosenDeckId == 'reference', 1, 0))
d
The sample size is 70.
cellMeans <- d %>%
group_by(subject, difficulty, lagDifficulty) %>%
summarize(srd = mean(selRefDeck)) %>%
group_by(difficulty, lagDifficulty) %>%
summarize(selRefDeck = mean(srd), se = sd(srd) / sqrt(n()))
cellMeans
cellMeans %>%
ggplot(aes(x = difficulty, y = selRefDeck, group = lagDifficulty)) +
geom_bar(stat = 'identity', aes(fill = lagDifficulty), color = 'black', position = position_dodge(width = 0.9)) +
geom_errorbar(aes(ymin = selRefDeck - se, ymax = selRefDeck + se), position = position_dodge(width = 0.9), width = 0.5) +
theme_bw() +
xlab('Difficulty') +
ylab('Proportion Selection of Reference Deck') +
ylim(0,1) +
scale_fill_manual(name = 'Lagged Difficulty', values = c('Easier than Reference' = 'Light Grey', 'Harder than reference' = 'Black')) +
theme(strip.background = element_rect(color = 'black', fill = 'white'),
legend.position = 'top')
Subject-wise cell means
d %>%
group_by(subject, lagDifficulty, difficulty) %>%
summarize(selRefDeck = mean(selRefDeck))
Omnibus Model
This is breaking because the factors aren’t fully between or within.
I think I’ll have to think about this one some more.
m1 <- ezANOVA(wid = subject, between = .(difficulty, lagDifficulty), dv = selRefDeck, data = d, detailed = TRUE)
## Warning: Converting "subject" to factor for ANOVA.
## Warning: The column supplied as the wid variable contains non-unique values
## across levels of the supplied between-Ss variables. Automatically fixing
## this by generating unique wid labels.
## Warning: Data is unbalanced (unequal N per group). Make sure you specified
## a well-considered value for the type argument to ezANOVA().
## Warning: Collapsing data to cell means. *IF* the requested effects are a
## subset of the full design, you must use the "within_full" argument, else
## results may be inaccurate.
## Coefficient covariances computed by hccm()
m1
## $ANOVA
## Effect DFn DFd SSn SSd F
## 1 difficulty 1 268 1.371235e+00 23.11448 1.589874e+01
## 2 lagDifficulty 1 268 9.725838e-04 23.11448 1.127659e-02
## 3 difficulty:lagDifficulty 1 268 3.323065e-05 23.11448 3.852915e-04
## p p<.05 ges
## 1 8.623838e-05 * 5.600144e-02
## 2 9.155100e-01 4.207505e-05
## 3 9.843541e-01 1.437653e-06
##
## $`Levene's Test for Homogeneity of Variance`
## DFn DFd SSn SSd F p p<.05
## 1 3 268 0.1498109 8.262032 1.619832 0.1850754
cs <- c(colnames(m1$ANOVA), 'n2p')
omni <- cbind(m1, data.frame(n2p = m1$ANOVA$SSn / (m1$ANOVA$SSn + m1$ANOVA$SSd)))
colnames(omni) <- cs
omni
Planned Comparisons
A work by Dave Braun
dab414@lehigh.edu